import {
  createRouter,
  createWebHistory,
  type RouteRecordRaw,
} from "vue-router";

// 扩充 RouteMeta 类型
declare module "vue-router" {
  interface RouteMeta {
    title: string;
  }
}

// 定义 routes
const routes: RouteRecordRaw[] = [
  {
    path: "/",
    redirect: { name: "now-playing" },
  },
  {
    path: "/films",
    name: "film-list",
    meta: { title: "电影列表" },
    redirect: { name: "now-playing" },
    component: () => import("./views/film/list/index.vue"),
    children: [
      {
        path: "nowPlaying",
        name: "now-playing",
        meta: { title: "正在热映" },
        component: () => import("./views/film/list/now-playing.vue"),
      },
      {
        path: "comingSoon",
        name: "coming-soon",
        meta: { title: "即将上映" },
        component: () => import("./views/film/list/coming-soon.vue"),
      },
    ],
  },
  {
    path: "/film/:id",
    name: "film-detail",
    meta: { title: "电影详情" },
    component: () => import("./views/film/detail/index.vue"),
  },
  {
    path: "/cinemas",
    name: "cinema-list",
    meta: { title: "影院列表" },
    component: () => import("./views/cinema/list/index.vue"),
  },
  {
    path: "/cinemas/search",
    name: "cinema-search",
    meta: { title: "影院搜索" },
    component: () => import("@/views/cinema/search/index.vue"),
  },
  {
    path: "/cinema/:id",
    name: "cinema-detail",
    meta: { title: "影院详情" },
    component: () => import("./views/cinema/detail/index.vue"),
  },
  {
    path: "/cinema/:id/film",
    name: "cinema-schedule",
    meta: { title: "影院影片排期" },
    component: () => import("@/views/cinema/schedule/index.vue"),
  },
  {
    path: "/center",
    name: "center",
    meta: { title: "个人中心" },
    component: () => import("./views/my/center.vue"),
  },
  {
    path: "/post",
    name: "post",
    meta: { title: "咨询" },
    component: () => import("./views/post/index.vue"),
  },
  {
    path: "/city",
    name: "city",
    component: () => import("@/views/city/index.vue"),
  },
];

// 创建路由器实例
console.log(import.meta.env.BASE_URL, '====')
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

// 默认导出路由器实例
export default router;
